#include "GameStep.h"
#include "Common.h"


GameStep* GameStep::create(const char *pszFileName)
{
	GameStep* p = new GameStep();
	if (p && p->initWithFile(pszFileName))
	{
		p->autorelease();
		return p;
	}

	CC_SAFE_DELETE(p);
	return p;
}

void GameStep::onPhyPosChange()
{

}

void GameStep::setPosition(const CCPoint &position)
{
	if (m_pBody == NULL)
	{
		return;
	}

	b2Vec2 pos(position.x / PTM_RATIO, position.y / PTM_RATIO);
	m_pBody->SetTransform(pos, m_pBody->GetAngle());
	CCSprite::setPosition(position);
}

b2Body* GameStep::CreateBody(b2World* world)
{
	b2BodyDef bodyDef;
	bodyDef.position.Set(0, 2.1f);
	bodyDef.type = b2_staticBody;
	bodyDef.gravityScale = 0;

	m_pBody = world->CreateBody(&bodyDef);

	b2FixtureDef fd;
	fd.restitution = 0;
	fd.density = 1;
	fd.filter.categoryBits = ECM_Step;
	fd.filter.maskBits = ECM_Hero;
	b2PolygonShape share;
	share.SetAsBox(128 / PTM_RATIO, 8 / PTM_RATIO);
	fd.shape = &share;
	m_pBody->CreateFixture(&fd);
	m_pBody->SetUserData(new MyUserData(this));

	return m_pBody;
}
